package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

/**
 * @pakager_name:controller
 * @description:
 * @author: 周铖鑫
 * @time: 2020/11/1 19:56
 */
@Controller
public class testController {
    @GetMapping("/test")
    public String test()throws Exception{
        int i=5/0;
        return "success";
    }
    @GetMapping("/find")
    public String find()throws Exception{
       try{
           int i=5/0;
           return "success";
       }catch (Exception e){
            throw new IOException("查询数据失败");
       }
    }
    @GetMapping("/find2")
    public String find2()throws Exception {
            int i = 5 / 0;
            return "success";
    }

    @ExceptionHandler(value = Exception.class)
    public ModelAndView testExceptionHandler(Exception e){
        System.out.println("testExceptionHandler....");
        ModelAndView modelAndView =new ModelAndView();
        modelAndView.addObject("ex",e);
        modelAndView.setViewName("error");
        return modelAndView;
    }
}

